<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>修改系统模块</title>
    <base href="<%=basePath%>"/>
    <%@ include file="../../cuv_include.jsp"%>
    <style type="text/css">
  		fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
  		form label {font-weight:bold;}
    	table{margin:10px 10px};
  		td{line-height: 40px;}
		input[type="text"]{width:250px;}
		input[type="password"]{width:250px;}
		input[type="textarea"]{width:250px;}   		
    </style>
    
	<script type="text/javascript">
	  $(document).ready(function(){
        var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
        $("#moduleForm").submit(function(){
            $(this).ajaxSubmit(options);
            return false;
        });
	  });
	  
	  function changeSelect(){
		  var module = $("#parentId").val();
		   if(module==""){
			 $('#url').attr('value','');
		     $('#url').attr('disabled','disabled');
		   }else{
		     $('#url').removeAttr('disabled'); 
		   }
	  }

        function beforeSubmit() {
            if(isEmpty($("#alias").val())) { alert("别名不能为空！"); return false; }
            if(!validateSize($("#alias").val(), 2, 32)) { alert("别名不符合规格！"); return false; }

            var url = $("#url").val();
            var module = $("#parentId").val();
            if(module !=""){
              if($.trim(url) == "") {
                 alert("URL地址不能为空！");
                 return false;
              }
            }

            if(isEmpty($("#orderNum").val())) { alert("顺序不能为空！"); return false; }
            if(isNaN($("#orderNum").val())) { alert("顺序必须是数字！"); return false; }

            return true;
        }

      function process(responseJson) {
        if(responseJson.code == 0) {
            $('#error_label').text("错误信息：" + responseJson.message);
            $("#p_error").show();
            return;
        }
        var qs = $("#qs").val();
        location.href = "<%=basePath%>system/module/list.do?" + qs;
      }
	</script>    
  </head>
  
  <body>
  <div>
    <fieldset>
      <legend>修改模块：</legend>
      <form id="moduleForm" method="post" action="system/module/edit.do">
        <input id="qs" name="qs" type="hidden" value="${qs}"/>
        <input type="hidden" name="id" value="${module.id}" />
        <input type="hidden" name="enname" value="${module.enname}" />
        <input type="hidden" name="status" value="${module.status}" />
        <input type="hidden" name="createTime" value="${module.createTime}" />
        <p id = "p_error" style = "margin:10px 10px;">
            <label id="error_label" style="color:red;"></label>
        </p>
        <table>
          
          <tr>
            <td><label for="enname">英文名称：</label></td>
            <td>
            	<input type="text" name="enname" disabled="disabled" id="enname" value="${module.enname }" />
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            	<label for="enname">只能由字母、数字、下划线组成，字母开始，6～32位 </label>
            </td>
          </tr>
         <tr>
            <td><label for="alias">别名：</label></td>
            <td>
            	<input type="text" name="alias"  id="alias" value="${module.alias }" />
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            	<label for="alias">2～32位</label>
            </td>
          </tr>
          <tr>
            <td><label>所属父模块：</label></td>
            <td>
                <select id="parentId" name="parentId" style="width:250px;" onchange="changeSelect()">
                  <option value="" style="color:red">选择父模块</option>
                <c:forEach var="pmodule" items="${pModuleList}" varStatus="status">
                  <c:if test="${pmodule.id != module.id }">  
                    <option value="${pmodule.id}" <c:if test="${pmodule.id == module.parentId}">selected="selected"</c:if>>${pmodule.alias}</option>
                  </c:if>
                </c:forEach>
              	</select> 
            </td>
          </tr>           
          <tr>
            <td><label for="url">URL：</label></td>
            <td>
            	<input type="text" name="url" id="url" value="${module.url }" <c:if test="${module.url == null}">disabled="disabled"</c:if> />
            </td>
          </tr>
          <tr>
            <td><label for="orderNum">顺序：</label></td>
            <td>
              <input type="text" name="orderNum" id="orderNum" value="${module.orderNum }" />
                <font color="red">&nbsp;*&nbsp;&nbsp;</font>
                <label for="alias">必须是数字</label>
            </td>
          </tr>          
           <tr>
            <td valign="top"><label for="remark">描述：</label></td>
            <td valign="top"><textarea name="remark" id="remark" cols="40" rows="3"><c:out value="${module.remark }"/></textarea></td>
          </tr>                   
          <tr>
            <td></td>
            <td>
            	<input type="submit" id="btn_update" value="提交" style="width:80px;" />
            	<input type="button" id="btn_back" value="返回" onclick="history.back();" style="width:80px;" />
            </td>
          </tr>
        </table>
      </form>
    </fieldset>
  </div>    
  </body>
</html>